import { reqDetailInfo } from "@/api/index.js"


const detail = {
    namespaced: true,  // 开启命名空间
    state: {
        detailInfo: {}
    },
    mutations:{
        RECEIVE_DETAILINFO(state,detailInfo){
            state.detailInfo = detailInfo
        }
    },
    actions: {
        async getDetailInfo({commit},skuId){
            const result = await reqDetailInfo(skuId)
            if(result.code === 200){
                commit('RECEIVE_DETAILINFO',result.data)
            }
        }
    },
    getters:{
        // 简化操作
        categoryView(state){
            return state.detailInfo.categoryView || {}
        },
        skuInfo(state){
            return state.detailInfo.skuInfo || {}
        },
        spuSaleAttrList(state){
            return state.detailInfo.spuSaleAttrList || []
        }
    }
}

export default detail